<template>
  <el-config-provider>
    <div class="app">
      <el-container>
        <el-header height="60px">
          <div class="header-content">
            <router-link to="/" class="logo">
              <el-icon>
                <Folder />
              </el-icon>
              <span>腾讯云对象存储资源浏览器</span>
            </router-link>
            <nav class="main-nav">
              <router-link to="/" class="nav-item">首页</router-link>
              <router-link to="/folder" class="nav-item">文件管理</router-link>
              <a href="/medical" target="_blank" class="nav-item">医疗视频库</a>
              <router-link to="/about" class="nav-item">关于</router-link>
            </nav>
            <div class="user-actions">
              <el-button type="primary" size="small" @click="showTransferPanel">
                传输
                <el-icon class="el-icon--right"><upload-filled /></el-icon>
              </el-button>
            </div>
          </div>
        </el-header>

        <el-main>
          <router-view />
        </el-main>

        <el-footer height="40px">
          <div class="footer-content">
            <p>© {{ new Date().getFullYear() }} 腾讯云对象存储资源浏览器</p>
          </div>
        </el-footer>
      </el-container>
      <TransferManager id="global-transfer-manager" ref="transferManager" />
    </div>
  </el-config-provider>
</template>

<script setup>
import { Folder } from '@element-plus/icons-vue'
import TransferManager from '@/components/TransferManager.vue'
import { provide, ref, onMounted } from 'vue'

const transferManager = ref(null)

// 提供传输管理器给所有子组件
provide('transferManager', transferManager)

onMounted(() => {
  // 设置全局访问方法
  window.$app = {
    transferManager: transferManager.value
  }

  // 确保window.transferManager可用
  if (transferManager.value) {
    console.log('注册传输管理器到全局对象，可用方法:', Object.keys(transferManager.value));

    // 直接引用整个对象，而不是单独映射方法
    window.transferManager = transferManager.value;

    // 添加调试信息
    console.log('传输管理器初始化状态:', {
      hasAddTask: typeof window.transferManager.addTask === 'function',
      hasUpdateTask: typeof window.transferManager.updateTask === 'function',
      hasCompleteTask: typeof window.transferManager.completeTask === 'function',
      hasShowPanel: typeof window.transferManager.showTransferPanel === 'function',
    });
  } else {
    console.error('传输管理器组件未初始化，无法设置全局引用');
  }
})
</script>

<style scoped>
.app {
  min-height: 100vh;
}

.el-header {
  background-color: #409EFF;
  color: white;
  line-height: 60px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.logo {
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  color: white;
  text-decoration: none;
  transition: transform 0.2s ease;
}

.logo:hover {
  transform: scale(1.03);
}

.logo .el-icon {
  margin-right: 10px;
  font-size: 24px;
}

.main-nav {
  display: flex;
  gap: 30px;
  align-items: center;
  height: 100%;
}

.nav-item {
  position: relative;
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 16px;
  font-weight: 500;
  padding: 0 5px;
  transition: all 0.3s ease;
  height: 60px;
  display: flex;
  align-items: center;
}

.nav-item:hover {
  color: white;
}

.nav-item::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 3px;
  background-color: white;
  transition: width 0.3s ease;
}

.nav-item:hover::after,
.router-link-active.nav-item::after {
  width: 100%;
}

.router-link-active.nav-item {
  color: white;
  font-weight: 600;
}

.user-actions .el-button {
  margin-left: 10px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.user-actions .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.el-main {
  padding: 20px;
  background-color: #f5f7fa;
}

.el-footer {
  background-color: #f5f7fa;
  color: #909399;
  text-align: center;
  line-height: 40px;
  border-top: 1px solid #e4e7ed;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
}
</style>